package genetic.q3;

import java.io.*;
import java.util.StringTokenizer;

public class ReadFile {

	public boolean[][] matrix;
	public int size;
	public int max;

	public ReadFile(){

	}

	public void openFile(String filename){
		try {
			File f = new File(filename);
			BufferedReader input =  new BufferedReader(new FileReader(f));
			String line = null;
			int edges = 0;
			while (( line = input.readLine()) != null){
				if(line.startsWith("p")){
					StringTokenizer st = new StringTokenizer(line);
					while (st.hasMoreTokens()) {
					   if(st.nextToken().equals("edge")){
						   size = Integer.parseInt(st.nextToken());
						   edges = Integer.parseInt(st.nextToken());
						   matrix = new boolean[size][size];
					   }
					}
				}
				else if(line.startsWith("e")){
					StringTokenizer st = new StringTokenizer(line);
					while (st.hasMoreTokens()) {
					   if(st.nextToken().equals("e")){
						   int source = Integer.parseInt(st.nextToken());
						   int sink = Integer.parseInt(st.nextToken());
						   matrix[source-1][sink-1]=true;
						   matrix[sink-1][source-1]=true;
					   }
					}
				}
			}
			max = (int)((1+ Math.sqrt(1+(8*(double)edges)))/2);
		}catch (Exception e) {
		}
	}
}
